package com.example.kafka.exception.poison;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 处理毒丸消息的Controller
 */
@RestController
@RequestMapping("/api/poison-message")
@RequiredArgsConstructor
public class PoisonMessageController {

    private final PoisonMessageService poisonMessageService;

    /**
     * 用例1: 模拟格式错误的消息
     */
    @PostMapping("/invalid-format")
    public ResponseEntity<String> testInvalidFormat(@RequestBody String message) {
        return ResponseEntity.ok(poisonMessageService.handleInvalidFormat(message, null));
    }

    /**
     * 用例2: 模拟业务规则验证失败
     */
    @PostMapping("/business-rule-violation")
    public ResponseEntity<String> testBusinessRuleViolation(@RequestBody String message) {
        return ResponseEntity.ok(poisonMessageService.handleBusinessRuleViolation(message, null));
    }

    /**
     * 用例3: 模拟依赖服务不可用
     */
    @PostMapping("/dependency-unavailable")
    public ResponseEntity<String> testDependencyUnavailable(@RequestBody String message) {
        return ResponseEntity.ok(poisonMessageService.handleDependencyUnavailable(message, null));
    }

    /**
     * 用例4: 模拟数据一致性错误
     */
    @PostMapping("/data-inconsistency")
    public ResponseEntity<String> testDataInconsistency(@RequestBody String message) {
        return ResponseEntity.ok(poisonMessageService.handleDataInconsistency(message, null));
    }

    /**
     * 用例5: 模拟权限验证失败
     */
    @PostMapping("/authorization-failure")
    public ResponseEntity<String> testAuthorizationFailure(@RequestBody String message) {
        return ResponseEntity.ok(poisonMessageService.handleAuthorizationFailure(message, null));
    }
}
